﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Macds.Test.Core.Task.Mocks;
using Macds.Core.Task;

namespace Macds.Test.Core.Task
{
    [TestClass]
    public class TaskElementTest
    {
        public bool KeepRunning { get; set; }

        [TestMethod]
        public void SetTimerTest()
        {
            var element = new CustomerElement();
            element.OnTimerElapsed += new Macds.Core.Task.TaskElementEventHandler(TaskElementOnEvent);
            
            Assert.IsTrue(element.NewInstance);
            element.SetTimer(1000);
            element.Start();

            KeepRunning = true;
            while (KeepRunning)
            {
                System.Threading.Thread.Sleep(1500);
            }

            Assert.IsFalse(element.NewInstance);
        }

        private void TaskElementOnEvent(TaskElement element)
        {
            KeepRunning = false;
        }
    }
}
